package com.test.enum_my.demo2;

import java.util.HashMap;
import java.util.Map;

public enum ColorEnum {
    RED(1){
        @Override
        public void getInfo() {
            System.out.println("red");
        }
    },
    GREEN(2){
        @Override
        public void getInfo() {
            System.out.println("green");
        }
    },
    BLANK(3){
        @Override
        public void getInfo() {
            System.out.println("blank");
        }
    },
    YELLOW(4){
        @Override
        public void getInfo() {
            System.out.println("yellow");
        }
    };

    private Integer value;

    private static Map<Integer,ColorEnum> map = new HashMap<>();
    static {
        for (ColorEnum t : ColorEnum.values()){
            map.put(t.getValue(),t);
        }
    }

    ColorEnum(Integer value) {
        this.value = value;
    }

    public abstract void getInfo();

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public static ColorEnum getColorEnum(Integer key){
        if (key == null) return null;
        return map.get(key);
    }
}